package cc.shacocloud.redis.study.util.redis;

import cn.hutool.core.date.DateUtil;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Redis 锁操作返回对象
 */
@Getter
public class RLock {

    /**
     * 锁名称
     */
    private final String lockName;

    /**
     * 可重入凭证
     */
    private final String reentrantCertificate;

    /**
     * 过期时间
     */
    private final Date expireDate;

    /**
     * 尝试锁定状态  true上锁成功  反之则失败 (在调用{@linkplain RedisLockUtil#tryLock}方法时)
     * or
     * 尝试解锁状态  true解锁成功  反之则失败 (在调用{@linkplain RedisLockUtil#tryUnlock}方法时)
     */
    private final boolean status;

    public RLock(String lockName, String reentrantCertificate, long leaseTime, @NotNull TimeUnit unit, boolean status) {
        this.lockName = lockName;
        this.reentrantCertificate = reentrantCertificate;
        this.status = status;
        this.expireDate = DateUtil.offsetMillisecond(DateUtil.date(), (int) unit.toMillis(leaseTime));
    }


}
